/**
 * File ini tidak memiliki lisensi apapun.
 * Entah mau kalian bajak, pake, jual
 * gue gak peduli
 */

#include "UiPack.hpp"
#include <iostream>

void createNPC(void *param)
{
	UiToolWindow *test = new UiToolWindow(L"Tambah NPC", 215, 130);
	
	UiLabel   *label = new UiLabel(test, L"Nama NPC: ", 80, 20, 5, 10);
	UiTextbox  textbox(test->getHandle(), 120, 20, 85, 10);
			  
	UiLabel   *label2 = new UiLabel(test, L"Nama MAP: ", 80, 20, 5, 33);
	UiTextbox  textbox2(test->getHandle(), 120, 20, 85, 33);
			  
	UiLabel   *label3 = new UiLabel(test, L"Sprite ID: ", 80, 20, 5, 56);
	UiTextbox  textbox3(test->getHandle(), 32, 20, 85, 56);
			  
	UiLabel   *labelX = new UiLabel(test, L"X: ", 20, 20, 5, 79);
	UiTextbox  textboxX(test->getHandle(), 25, 20, 30, 79);
			  
	UiLabel   *labelY = new UiLabel(test, L"Y: ", 20, 20, 67, 79);
	UiTextbox  textboxY(test->getHandle(), 25, 20, 92, 79);
	UiButton  *ok = new UiButton(test, L"Tambah", 82, 43, 123, 57);

	test->show();
	test->setOwner(reinterpret_cast<UiWindow*>(param));
	test->mainFocus(true);
}

void createMSG(void *param)
{
	MessageBox(reinterpret_cast<UiButton*>(param)->getHandle(), L"Halo Test buat pesan!", L"MSG", MB_OK);
}

void test(void *param)
{
	MessageBox(reinterpret_cast<UiButton*>(param)->getHandle(), L"Halo!", L"MSG", MB_OK);
}

void quit(UiButton *btn)
{
	UiApp::getCurrentApp()->quit();
}

// Sizer
int main(int argc, char **argv)
{
	UiApp app;

	UiWindow *mainWindow = new UiWindow(L"Hello WOrld! This is ASIDE!", 640, 480);
	mainWindow->setMinSize(640, 480);

	// Menu Bar ---------------------------------------------------
	UiMenubar *menubar = new UiMenubar();
	mainWindow->setMenubar(menubar);

	UiMenubarItem *item1 = new UiMenubarItem(L"New", L"PNG_NEW", test, mainWindow);
	menubar->addItem(item1);
	item1->showTooltip(L"Buat Script baru");

	UiMenubarItem *item2 = new UiMenubarItem(L"Open", L"PNG_OPEN", test, mainWindow);
	menubar->addItem(item2);
	item2->showTooltip(L"Buka script");

	UiMenubarItem *item3 = new UiMenubarItem(L"Save", L"PNG_SAVE");
	menubar->addItem(item3);
	item3->showTooltip(L"Simpan script");

	// Main Window ------------------------------------------------
	UiSizer *mySizer = new UiSizer(mainWindow, UiSizer::UI_SIZER_HORIZONTAL);

	UiSizer *toolPanel = new UiSizer(UiSizer::UI_SIZER_VERTICAL);
	mySizer->attach(toolPanel).setSize(-1, -1).setAlign(UiSizer::UI_SIZER_ALIGN_LEFT);

	// Tool Window ------------------------------------------------
	UiToolWindow *toolWindow = new UiToolWindow(L"ToolWindow", 96, 200);

	UiSizer *sizer = new UiSizer(toolWindow, UiSizer::UI_SIZER_HORIZONTAL);

	UiButton *butx1 = new UiButton(L"");
	butx1->setImage(L"PNG_NEWNPC");
	butx1->setCallback(createNPC, mainWindow);
	butx1->showTooltip(L"Buat NPC baru");

	UiButton *butx2 = new UiButton(L"");
	butx2->setImage(L"PNG_OPEN");

	UiButton *butx3 = new UiButton(L"");
	butx3->setImage(L"PNG_OPEN");

	UiButton *butx4 = new UiButton(L"");
	butx4->setImage(L"PNG_OPEN");

	UiButton *butx5 = new UiButton(L"");
	butx5->setImage(L"PNG_MSG");
	butx5->setCallback(createMSG, mainWindow);
	butx5->showTooltip(L"Tambahkan pesan");

	UiButton *butx6 = new UiButton(L"");
	butx6->setImage(L"PNG_OPEN");

	UiButton *butx7 = new UiButton(L"");
	butx7->setImage(L"PNG_OPEN");

	UiButton *butx8 = new UiButton(L"");
	butx8->setImage(L"PNG_OPEN");
	
	UiSizer *toolLeft = new UiSizer(UiSizer::UI_SIZER_VERTICAL);
	UiSizer *toolRight = new UiSizer(UiSizer::UI_SIZER_VERTICAL);
	sizer->attach(toolLeft).setMargin(10, 10, 10, 10).setSize(32, -1);
	sizer->attach(toolRight).setMargin(0, 10, 10, 10).setSize(32, -1);

	toolLeft->attach(butx1).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolLeft->attach(butx2).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolLeft->attach(butx3).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolLeft->attach(butx4).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolRight->attach(butx5).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolRight->attach(butx6).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolRight->attach(butx7).setMargin(0, 0, 0, 10).setSize(32, 32);
	toolRight->attach(butx8).setMargin(0, 0, 0, 10).setSize(32, 32);

	toolPanel->attach(toolWindow).setSize(96, -1).setAlign(UiSizer::UI_SIZER_ALIGN_LEFT);

	mainWindow->show();

	return app.run();
}